package com.qkl.qkl.service;

import com.alibaba.fastjson.JSONObject;
import com.qkl.qkl.common.Dto;
import com.qkl.qkl.util.Conts;
import com.qkl.qkl.util.RequestDataUtil;
import com.qkl.qkl.util.SimpleHttpClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**共享信息service
 * Created by with Intellij IDEA
 * Author : tianhaoyi
 * Date : 2018/7/20
 * Time : 13:32
 */
@Service
public class ISSService {

    /**
     * 共享信息新增/追加
     * @param dto
     * @return
     * @throws Exception
     */
    public  String issAppend(Dto dto) throws Exception {
        String request = RequestDataUtil.issAppendRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.ISS_APPEND_URL, request);

//        System.out.println("result===="+result);
        JSONObject jsonObject = JSONObject.parseObject(result);

        if(StringUtils.isBlank(jsonObject.getString("sign"))){

            dto.put("sign_str",jsonObject.getString("sign_str"));

            request = RequestDataUtil.issAppendRequest(dto);
            result = httpClient.post(Conts.ISS_APPEND_URL, request);
        }
//        System.out.println("result----"+result);
        return result;
    }

    /**
     * 共享信息查询
     * @param dto
     * @return
     * @throws Exception
     */
    public  String issQuery(Dto dto) throws Exception {
        String request = RequestDataUtil.issQueryRequest(dto);
        SimpleHttpClient httpClient = new SimpleHttpClient();
        String result = httpClient.post(Conts.ISS_QUERY_URL, request);
        return result;
    }
}
